package com.xgz;

import com.xgz.config.AppConfig;
import com.xgz.service.aop.Aop;
import com.xgz.service.circular.A;
import com.xgz.service.listener.AppEventListener;
import com.xgz.service.listener.AppEventPublisher;
import com.xgz.service.listener.ChangeEvent;
import com.xgz.service.listener.MessageEvent;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * 主程序
 * @author xgz
 */
public class Main {
	public static void main(String[] args) {
	//	ApplicationContext applicationContext = new ClassPathXmlApplicationContext("xgz.xml");

		ApplicationContext app =
				new AnnotationConfigApplicationContext(AppConfig.class);
		Aop aop = (Aop) app.getBean("aop");

		aop.annoMethod();
		aop.aopMethod();
		// 发布事件
		AppEventPublisher appEventPublisher = (AppEventPublisher)app.getBean("appEventPublisher");
		appEventPublisher.publish(new A());
		appEventPublisher.publish(new MessageEvent("hello 你好"));
		appEventPublisher.publish(new ChangeEvent(appEventPublisher, "sending..."));
		// 在 AppEventListener 进行事件监听

/*		String[] beanDefinitionNames = app.getBeanDefinitionNames();
		System.out.println("===================== 下面是所有bean ==========================");
		for (String name : beanDefinitionNames) {
			System.out.println(name + ":" + "\t\t"+app.getBean(name));
		}*/
	}
}